import UserService from '@/service/UserService';
import UniUtil from '@/utils/UniUtil';
import Util from '@/utils/Util';
import Constant, { TopBar } from '@/constant/Constants';
import { QrcodeResponse } from '@/protocol/response/QrcodeResponse';
import LoggerUtil from '@/utils/LoggerUtil';
import CommonService from '@/service/CommonService';
import StringUtil from '@/utils/StringUtil';
import { UserRequest } from '@/protocol/request/UserRequest';
import { UserResponse } from '@/protocol/response/UserResponse';
import { UserInfo } from "@/model/UserInfo";
import { MyVue } from "@/common/MyVue";
import { Component } from "vue-facing-decorator";
@Component
export default class ScoreList extends MyVue {
    selectIndex: number = 0;
    dataList = new Array<UserResponse.AccountInfo>();
    request = new UserRequest.AccountInfoList();
    translateX = {
        'transform': '',
        '-webkit-transform': '',
        '-moz-transform': ''
    };
    user = new UserInfo.User();
    onLoad() {
        uni.setNavigationBarTitle({ title: TopBar.SCORE_LIST });
        this.request.pageSize = 20
    }

    setTabTranslateX() {
        Object.keys(this.translateX).forEach(key => {
            let val = this.translateX[key];
            this.translateX[key] = StringUtil.format('translateX({})', [this.selectIndex * 100 + '%']);
        })
    }
    onTabSelect(e) {
        if (this.selectIndex == e.currentTarget.dataset.index) {
            return;
        }
        this.selectIndex = e.currentTarget.dataset.index;
        this.setTabTranslateX();
        this.request.type = e.currentTarget.dataset.type;
        this.init();

    }

    async loadPost() {
        this.setTabTranslateX();
        this.init();
    }

    onSearch() {
        this.init();
    }
    onShareAppMessage() {
        let user = UserService.getUser();
        let uid = Util.isEmpty(user) ? 0 : user.uid;
        return UniUtil.onShareAppMessage('', '', "/pages/home/home?uid=" + uid);
    }
    async init() {
        this.dataList.length = 0;
        this.request.pageIndex = 1;
        this.load();
    }
    async load() {
        let res = await UserService.queryScoreList(this.request);
        if (Util.isEmpty(res)) {
            return;
        }
        Util.copyList(this.dataList, res, UserResponse.AccountInfo);

    }
    onReachBottom() {
        this.request.pageIndex += 1;
        this.load();
    }

}